using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;

public class AchieveSubject : MonoBehaviour
{
	[SerializeField]
	private AchieveItem m_AchieveItemPrefab;

	[SerializeField]
	private GridLayoutGroup m_Root;

	[SerializeField]
	private Text m_Progress;

	private void Start()
	{
		int num = 0;
		int num2 = 0;
		var items = AchieveConfiguration.achieveDictionary.OrderBy(value => int.Parse(value.Value.level.Split('-')[0])).ThenBy(value => int.Parse(value.Value.level.Split('-')[1])).ToArray();
		foreach (KeyValuePair<int, AchieveInfo> item in items)
		{
			num2++;
			AchieveItem achieveItem = SupportTools.AddChild<AchieveItem>(m_Root.gameObject, m_AchieveItemPrefab.gameObject);
			int key = item.Key;
			achieveItem.parentPanel = this;
			achieveItem.achieveInfo = item.Value;
			achieveItem.achieveName.text = item.Value.name;
			achieveItem.description.text = HOLocalizationConfiguration.GetValue(item.Value.DescriptionID);
			achieveItem.achieveIcon.sprite = Resources.Load<Sprite>("UI/LaunchScene/AchieveIcon/" + item.Value.IconName);
			achieveItem.takeRewardBtn.transform.parent.gameObject.SetActive(item.Value.prizeItemId > 0);
			if (ConstantData.achieveRecords[key] < item.Value.goal)
			{
				achieveItem.finishFlag.gameObject.SetActive(value: false);
				achieveItem.progress.text = ConstantData.achieveRecords[key] + "/" + item.Value.goal;
				achieveItem.gray = true;
			}
			else
			{
				achieveItem.gray = false;
				achieveItem.progress.gameObject.SetActive(value: false);
				if (ConstantData.achieveRecords.IsTakenReward(key))
				{
					achieveItem.finishFlag.gameObject.SetActive(value: true);
					achieveItem.takeRewardBtn.transform.parent.gameObject.SetActive(value: false);
				}
				else
				{
					achieveItem.takeRewardBtn.transform.parent.gameObject.SetActive(value: true);
				}
				num++;
			}
		}
		m_Progress.text = num + "/" + AchieveConfiguration.achieveDictionary.Count;
		RectTransform component = m_Root.GetComponent<RectTransform>();
		Vector2 cellSize = m_Root.cellSize;
		float x = cellSize.x;
		float num3 = num2;
		Vector2 cellSize2 = m_Root.cellSize;
		float num4 = num3 * cellSize2.y;
		float num5 = num2 - 1;
		Vector2 spacing = m_Root.spacing;
		component.sizeDelta = new Vector2(x, num4 + num5 * spacing.y);
	}

	public void SetBannerVisible(int i)
	{
		switch (i)
		{
			case 0:
				AdManagerOld.instance.curAd.HideBanner();
				break;
			case 1:
				AdManagerOld.instance.curAd.HideBanner();
				break;
		}
	}

	public void OpenGetItemWnd(int itemId, int number, Action onGetItem)
	{
		UIADViewWnd.ShowGetItem(itemId, number, onGetItem);
	}

	public void ClickBack()
	{
		AdManagerOld.instance.curAd.HideBanner();
	}
}
